
namespace Derm.Render.Shaders.Font {

	/// <summary>
	/// Predefined shader program.
	/// </summary>
	public class FontShader : ShaderProgram
	{
		#region Constructors

		/// <summary>
		/// Construct a FontShader.
		/// </summary>
		public FontShader() : base("FontShader")
		{
			// Attach all required vertex shaders
			AttachShader(FontVertexShader.LibraryId, ShaderObject.Stage.Vertex);
			AttachShader(ProjectRigidVertex.LibraryId, ShaderObject.Stage.Vertex);

			// Attach all required fragment shaders
			AttachShader(FontFragmentShader.LibraryId, ShaderObject.Stage.Fragment);
		}

		/// <summary>
		/// A string that identifies this ShaderProgram implementation in ShaderLibraryConfiguration.
		/// </summary>
		public static readonly string LibraryId = "FontShader";

		#endregion

	}

	/// <summary>
	/// Shader source generated from MainVertex shader source file.
	/// </summary>
	public class FontVertexShader : ShaderObject
	{
		#region Constructors

		/// <summary>
		/// Construct a FontVertexShader defining itself a vertex shader.
		/// </summary>
		public FontVertexShader() : base(Stage.Vertex, "Derm/Shaders/Font/MainVertex") { }

		/// <summary>
		/// A string that identifies this ShaderObject implementation in ShaderLibraryConfiguration.
		/// </summary>
		public static readonly string LibraryId = "Derm.Shaders.Font.FontVertexShader";

		#endregion

		#region ShaderObject Overrides

		/// <summary>
		/// The only stage that this ShaderObject can link.
		/// </summary>
		public static readonly Stage LibraryStage = Stage.Vertex;

		/// <summary>
		/// The source string read from Derm/Shaders/Font/MainVertex.
		/// </summary>
		protected override string[] Source { get { return (sShaderSource); } }

		/// <summary>
		/// The source string read from Derm/Shaders/Font/MainVertex.
		/// </summary>
		private static readonly string[] sShaderSource = new string[] {
			"",
			"//  Copyright (C) 2011-2012 Luca Piccioni",
			"// ",
			"//  This program is free software: you can redistribute it and/or modify",
			"//  it under the terms of the GNU General Public License as published by",
			"//  the Free Software Foundation, either version 3 of the License, or",
			"//  (at your option) any later version.",
			"// ",
			"//  This program is distributed in the hope that it will be useful,",
			"//  but WITHOUT ANY WARRANTY; without even the implied warranty of",
			"//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the",
			"//  GNU General Public License for more details.",
			"// ",
			"//  You should have received a copy of the GNU General Public License",
			"//  along with this program.  If not, see <http://www.gnu.org/licenses/>.",
			"",
			"#include </Derm/Shaders/Compatibility>",
			"",
			"#include </Derm/Shaders/IProjectVertex>",
			"",
			"// --- Shader inputs and outputs",
			"",
			"// This shader input interface",
			"BEGIN_INPUT_BLOCK(FontVertexShaderInputs)",
			"	// Vertex position",
			"	ATTRIBUTE vec2 ds_VertexPosition;",
			"END_INPUT_BLOCK()",
			"",
			"// This shader output interface",
			"BEGIN_OUTPUT_BLOCK(FragmentShaderVaryings)",
			"	// Processed vertex texture coordinate",
			"	SHADER_OUT vec2 ds_TexCoords;",
			"END_OUTPUT_BLOCK()",
			"",
			"// Font glyph texture offset",
			"uniform vec2 ds_FontPositionOffset;",
			"// Font glyph texture offset",
			"uniform vec2 ds_FontPositionScale;",
			"",
			"// Vertex shader entry point",
			"void main()",
			"{",
			"	// Font glyph vertex",
			"	gl_Position = ProjectVertexPosition(ds_VertexPosition * ds_FontPositionScale + ds_FontPositionOffset);",
			"	// Font texture",
			"	ds_TexCoords = ds_VertexPosition;",
			"}",
		};

		#endregion
	}

	/// <summary>
	/// Shader source generated from MainFragment shader source file.
	/// </summary>
	public class FontFragmentShader : ShaderObject
	{
		#region Constructors

		/// <summary>
		/// Construct a FontFragmentShader defining itself a fragment shader.
		/// </summary>
		public FontFragmentShader() : base(Stage.Fragment, "Derm/Shaders/Font/MainFragment") { }

		/// <summary>
		/// A string that identifies this ShaderObject implementation in ShaderLibraryConfiguration.
		/// </summary>
		public static readonly string LibraryId = "Derm.Shaders.Font.FontFragmentShader";

		#endregion

		#region ShaderObject Overrides

		/// <summary>
		/// The only stage that this ShaderObject can link.
		/// </summary>
		public static readonly Stage LibraryStage = Stage.Fragment;

		/// <summary>
		/// The source string read from Derm/Shaders/Font/MainFragment.
		/// </summary>
		protected override string[] Source { get { return (sShaderSource); } }

		/// <summary>
		/// The source string read from Derm/Shaders/Font/MainFragment.
		/// </summary>
		private static readonly string[] sShaderSource = new string[] {
			"",
			"//  Copyright (C) 2011 Luca Piccioni",
			"// ",
			"//  This program is free software: you can redistribute it and/or modify",
			"//  it under the terms of the GNU General Public License as published by",
			"//  the Free Software Foundation, either version 3 of the License, or",
			"//  (at your option) any later version.",
			"// ",
			"//  This program is distributed in the hope that it will be useful,",
			"//  but WITHOUT ANY WARRANTY; without even the implied warranty of",
			"//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the",
			"//  GNU General Public License for more details.",
			"// ",
			"//  You should have received a copy of the GNU General Public License",
			"//  along with this program.  If not, see <http://www.gnu.org/licenses/>.",
			"",
			"#include </Derm/Shaders/Compatibility>",
			"",
			"// Processed vertex texture coordinate",
			"SHADER_IN vec2 ds_TexCoords;",
			"",
			"// Fragment color",
			"OUT vec4 ds_FragColor;",
			"",
			"// Font glyph texture",
			"uniform sampler2D ds_FontTexture;",
			"// Font glyph texture offset",
			"uniform vec2 ds_FontTextureOffset;",
			"// Font glyph texture offset",
			"uniform vec2 ds_FontTextureScale;",
			"",
			"// Fragment shader entry point",
			"void main()",
			"{",
			"	ds_FragColor = TEXTURE_2D(ds_FontTexture, ds_TexCoords * ds_FontTextureScale + ds_FontTextureOffset);",
			"}",
		};

		#endregion
	}

}

